#!/bin/sh

VERSION=$(cat ./data/version)
DIR=$(dirname $0)

cd $DIR 
# 编译
echo "开始编译"
mkdir build
cd build
qmake ../src
make
cd ..
echo "编译完成"
echo "-------------------"
echo "更新翻译"
lrelease ./translations/*.ts

#打包
echo "构建软件包"
mkdir -p ./deb_uos/opt/apps/com.appimage-installer/files/translations/
mkdir -p ./deb_uos/opt/apps/com.appimage-installer/entries/icons/hicolor/scalable/apps
cp ./image/logo/* ./deb_uos/opt/apps/com.appimage-installer/entries/icons/hicolor/scalable/apps/
cp ./build/appimage-installer ./deb_uos/opt/apps/com.appimage-installer/files/
cp ./translations/*.qm ./deb_uos/opt/apps/com.appimage-installer/files/translations/
cp -r ./data ./deb_uos/opt/apps/com.appimage-installer/files/
cp ./debian/control ./deb_uos/DEBIAN/
sed -i "s/<version>/$VERSION/g" ./deb_uos/DEBIAN/control
echo "-------包信息-------"
cat ./deb_uos/DEBIAN/control
echo "-------------------"

fakeroot dpkg -b ./deb_uos ./appimage-installer_amd64.deb

#清除模板中的文件
echo "清除文件"
rm ./deb_uos/opt/apps/com.appimage-installer/files/appimage-installer
rm -r ./deb_uos/opt/apps/com.appimage-installer/files/translations/*
rm -r ./deb_uos/DEBIAN/*
rm -r ./deb_uos/opt/apps/com.appimage-installer/files/data
rm -r ./deb_uos/opt/apps/com.appimage-installer/entries/icons/hicolor/scalable/apps/*
rm -r ./build
